package com.ym.utils;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import java.util.Objects;

public class RequestUtils {

    public static String getCurrentToken() {
        try {
            return ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes()))
                    .getRequest()
                    //这里必须跟网关保持一致
                    .getHeader("sa-token");
        } catch (Exception e) {
            return null;
        }
    }

    public static String getSameToken() {
        try {
            return ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes()))
                    .getRequest()
                    //这里必须跟网关保持一致
                    .getHeader("SA-SAME-TOKEN");
        } catch (Exception e) {
            return null;
        }
    }
}
